tongfusoft.customSearch = function() {
}

var csData={};
tongfusoft.customSearch.prototype = {

	queryCriteriaList : function() {

		common.post('queryCriteria/list', {}, function(data) {
			var queryCriteriaListHtml = "";
			$("#queryCriteriaList").empty();
			$.each(data.data, function(index, item) {
				csData[item.csId]=item.csData;
				
			
             
             if(item.csId==$("#csId").val()){
            	 queryCriteriaListHtml = queryCriteriaListHtml + '<li class="active">';
            	 queryCriteriaListHtml = queryCriteriaListHtml + '<a  href="javascript:void(0)" csId="' + item.csId+'" class="queryCriteria ">';
             }else{
            	 queryCriteriaListHtml = queryCriteriaListHtml + '<li>';
            	 queryCriteriaListHtml = queryCriteriaListHtml + '<a  href="javascript:void(0)" csId="' + item.csId+'" class="queryCriteria">';

             }
				queryCriteriaListHtml = queryCriteriaListHtml + '<span csId="' + item.csId+'"  class=" pull-right deleteBtn"><em class=" fa fa-trash"></em></span>';
				queryCriteriaListHtml = queryCriteriaListHtml + '<span csId="' + item.csId+'"  class=" pull-right editBtn "><em class=" fa fa-edit"></em></span>&nbsp;';

				queryCriteriaListHtml = queryCriteriaListHtml + '<span>' + item.csName+ '</span>';
			

				queryCriteriaListHtml = queryCriteriaListHtml + '</a></li>';

			});

			$("#queryCriteriaList").html(queryCriteriaListHtml);
			if($("#csId").val()!=''){
			new tongfusoft.docSearch().docList(1,10,csData[$("#csId").val()]);
			}
		});

	},
	queryCriteriaBtn : function() {

		$(".queryCriteria").click(function() {
			
			
			$.each($(".queryCriteria"), function(index, item) {
				
				$(item).parent().removeClass("active");
				
			});
			$(this).parent().addClass("active");
				new tongfusoft.myDoc().docList(1,10,csData[$(this).attr("csId")],$("#queryUrl").val());
			
			
		})

	},
	editPage:function(){
		
		$(".editBtn").click(function() {
			
			
			window.location.href = common.getContextPath("customSearch/editPage/"+$(this).attr("csId"));
		});
		
	},
	deleteBtn:function(){
		
		$(".deleteBtn").click(function() {
			var csId=  $(this).attr("csId");
		swal({
			title : "是否确认删除?",
			text : "",
			type : "warning",
			showCancelButton : true,
			confirmButtonColor : "#DD6B55",
			confirmButtonText : "删除",
			cancelButtonText : "取消",
			closeOnConfirm : true
		}, function() {
			common.ajaxSubmitOnSuccess({
				"csId" :csId
			}, 'queryCriteria/delete', function(data) {

				if (data.state == 'success') {

					window.location.href = common.getContextPath("customSearch");
				}

			}, "del")
		});

	
		});
		
	}

}

$(function() {

	
	new tongfusoft.myDoc().searchBtn();
	new tongfusoft.myDoc().detailBtn();
	
	
	var obj = new tongfusoft.customSearch();

	obj.queryCriteriaList();
	obj.queryCriteriaBtn();
	obj.editPage();
	obj.deleteBtn();
})